package com.tanhua.dubbo.api;

import com.tanhua.model.mongo.Announcement;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;


import java.util.List;

@Slf4j
@DubboService
public class AnnouncementAPImpl implements AnnouncementApi {

    @Autowired
    private MongoTemplate mongoTemplate;
    //查询公告列表
    @Override
    public List<Announcement> getAnnouncementApi(int page, int pagesize) {
        Query query = new Query();
            query.skip((page - 1) * pagesize).limit(pagesize).with(Sort.by(Sort.Order.desc("createDate")));
        List<Announcement> announcementList = mongoTemplate.find(query, Announcement.class);
        return announcementList;
    }
}
